package com.macro.mall.tiny.common.api;

import com.sun.org.apache.regexp.internal.RE;

/**
 * 通用的返回结果对象  ----  CommonResult通用类型
 * 后台往前台返回的结果
 */
public class CommonResult<T> {
    private long code;
    private String message;
    private T date;

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getDate() {
        return date;
    }

    public void setDate(T date) {
        this.date = date;
    }

    public CommonResult(){

    }
    public CommonResult(long code,String message,T date){
        this.code=code;
        this.message=message;
        this.date=date;
    }

    /**
     * 操作成功要返回的结果
     * @param date
     * @param message
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> success(T date,String message){
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(),message,date);
    }
    /**
     * 操作失败要返回的结果
     * @param //date
     * @param //message
     * @param <T>
     * @return
     * 第二种，传接口
     */
    public static <T> CommonResult<T> failed(T date, String message){
        return new CommonResult<>(ResultCode.FAILED.getCode(),message,null);
    }
//    public static <T> CommonResult<T> failed(IErrorCode iErrorCode){
//        return new CommonResult<T>(iErrorCode.getCode(),iErrorCode.getMessage(),null);
//    }

}
